home *** CD-ROM | disk | FTP | other *** search
- /* file manipulation routines not directly dependen on DS globals.
-
- Sam Madden
- June 17, 1993
- */
-
- #include "FileRoutines.h"
-
- /*-----------------------------------FSSpecToInfoRec()-----------------------------------*/
- //Routine to convert an FSSpec to a CInfoPBRec. So we can use PBGetCatInfo.
- OSErr FSSpecToInfoRec (FSSpec theSpec,CInfoPBRec *theInfoRec)
- {
- OSErr theErr;
-
- theInfoRec->hFileInfo.ioVRefNum = theSpec.vRefNum;
- theInfoRec->hFileInfo.ioDirID = theSpec.parID;
- theInfoRec->hFileInfo.ioNamePtr = (StringPtr) &theSpec.name;
- theInfoRec->hFileInfo.ioFDirIndex = 0; //Search by name
- theInfoRec->hFileInfo.ioCompletion = NULL;
-
- return (PBGetCatInfo (theInfoRec,false));
-
- }
-
- /*-----------------------------------MakeInvisible()-----------------------------------*/
-
- void MakeInvisible (FSSpec theSpec)
- {
- FInfo inf;
- OSErr err;
- CInfoPBRec pb;
-
- FSSpecToInfoRec (theSpec,&pb);
- err = pb.hFileInfo.ioResult;
- if (err)
- DebugStr ("\pCouldn't find file.");
- inf = pb.hFileInfo.ioFlFndrInfo;
- if (!(inf.fdFlags & fInvisible) && !err) {
- inf.fdFlags |= fInvisible; //set bit 14
- pb.hFileInfo.ioFlFndrInfo = inf;
- pb.hFileInfo.ioNamePtr = (StringPtr) &theSpec.name;
- pb.hFileInfo.ioDirID = theSpec.parID;
- pb.hFileInfo.ioVRefNum = theSpec.vRefNum;
- pb.hFileInfo.ioFDirIndex = 0; //Search by name
- pb.hFileInfo.ioCompletion = NULL;
- err = PBSetCatInfo (&pb,false);
- if (err)
- DebugStr ("\pCouldn't make file invisible.");
- FlushVol (NULL,theSpec.vRefNum);
- }
- }
-
- /*-----------------------------------MakeVisible()-----------------------------------*/
-
- void MakeVisible (FSSpec theSpec)
- {
- FInfo inf;
- OSErr err;
- CInfoPBRec pb;
-
- FSSpecToInfoRec (theSpec,&pb);
- err = pb.hFileInfo.ioResult;
- if (err)
- DebugStr ("\pCouldn't find file.");
- inf = pb.hFileInfo.ioFlFndrInfo;
- if ((inf.fdFlags & fInvisible) && !err) {
- inf.fdFlags -= fInvisible; //unset bit 14
- pb.hFileInfo.ioFlFndrInfo = inf;
- pb.hFileInfo.ioNamePtr = (StringPtr) &theSpec.name;
- pb.hFileInfo.ioDirID = theSpec.parID;
- pb.hFileInfo.ioVRefNum = theSpec.vRefNum;
- pb.hFileInfo.ioFDirIndex = 0; //Search by name
- pb.hFileInfo.ioCompletion = NULL;
- err = PBSetCatInfo (&pb,false);
- if (err)
- DebugStr ("\pCouldn't make file invisible.");
- FlushVol (NULL,theSpec.vRefNum);
- }
- }
-
- OSErr MoveFileToDesktop (FSSpec theFile)
- {
- short vref;
- long ddirid,vdirid;
- FSSpec dFoldSpec;
- Str31 volName;
- OSErr err;
-
- HGetVol (volName,&vref,&vdirid);
- err = FindFolder (vref,kDesktopFolderType,true,&vref,&ddirid);
- if (theFile.parID != ddirid){
- err = FSMakeFSSpec (vref,ddirid,0,&dFoldSpec); //we expect to find this
- if (err) goto done;
- err = FSpCatMove (&theFile,&dFoldSpec);
- }
- MakeVisible (theFile); //if it is on the desktop, it may be inviisble
- done:
- return err;
- }
-
- OSErr GetFinderInfo (FSSpec theFile,FInfo* finderInfo,FXInfo* finderXInfo)
- {
- CInfoPBRec theInfoRec;
- OSErr err;
-
- err = FSSpecToInfoRec (theFile,&theInfoRec);
- if (err) DebugStr ("\pFSSpecToInfoRec failed.");
- if (finderInfo != NULL)
- *finderInfo = theInfoRec.hFileInfo.ioFlFndrInfo;
- if (finderXInfo != NULL)
- *finderXInfo = theInfoRec.hFileInfo.ioFlXFndrInfo;
- return err;
- }
-
- OSErr SetFinderInfo (FSSpec theFile,FInfo* finderInfo,FXInfo* finderXInfo)
- {
- CInfoPBRec theInfoRec;
- OSErr err;
-
- err = FSSpecToInfoRec (theFile,&theInfoRec);
- if (err) DebugStr ("\pFSSpecToInfoRec failed.");
- if (finderInfo != NULL)
- theInfoRec.hFileInfo.ioFlFndrInfo = *finderInfo;
- if (finderXInfo != NULL)
- theInfoRec.hFileInfo.ioFlXFndrInfo = *finderXInfo;
- theInfoRec.hFileInfo.ioDirID = theFile.parID;
- theInfoRec.hFileInfo.ioNamePtr = (StringPtr)&theFile.name;
- theInfoRec.hFileInfo.ioVRefNum = theFile.vRefNum;
- err = PBSetCatInfo (&theInfoRec,false);
- if (err) DebugStr ("\pSetCatInfo failed.");
- return err;
- }
-